$(function(){
	var t = null;
	t = setTimeout(time);
	function time()
	{
		clearTimeout(t);
		var dt = new Date();
		var y=dt.getYear()+1900;
		var mm=dt.getMonth()+1;
		var d=dt.getDate();
		var day=dt.getDay();
		var h=dt.getHours();
		var m=dt.getMinutes();
		var s=dt.getSeconds();
		if(h<10){h="0"+h;}
		if(m<10){m="0"+m;}
		if(s<10){s="0"+s;}
		document.getElementById("timeShow").innerHTML =  +y+"年"+mm+"月"+d+"日"+" "+h+":"+m+":"+s+"";
        t = setTimeout(time,1000); //设定定时器，循环执行           
      }
    });
// 数据四舍五入
var rounding=function (count,times,bit) {
	return parseFloat(Number(count*times).toFixed(bit));
}
//  用于存储省级/市级内容
var provinceList,cityList
//  省列表生成
var cityDomList=function(data){
	console.log(data);
//      省份
provinceList=data.rows.provinceList;
//      市级
cityList=data.rows.cityList;
var str='',strcity='';
var newCityList=cityList[0].cityList;
for(var k in provinceList){
	str+='<option value="'+provinceList[k].code+'">'+provinceList[k].name+'</option>'
}
strcity+='<option value="'+newCityList[0].code+'">'+newCityList[0].name+'</option>'
$('#province').append(str);
$('#city').append(strcity);
$("#province option:nth-child(1)").attr("selected","selected");
$("#city option:nth-child(1)").attr("selected","selected");
var cityCode = $('#city').val();
var cityData={
	cityCode:cityCode
}
sessionStorage.setItem('cityCode',cityCode);
getData('post',ajaxUrl,cityechartUrl,cityData,cityechartInf);
var allInf={
	cityCode:sessionStorage.getItem('cityCode'),
	orderId:orderId
};
getData('post',ajaxUrl,mediaplanUrl,allInf,planInf,$('body'));

};
//  根据选择不同的省份显示不同的市级的option
$('#province').on('change',function(e){
	$('#city').children().remove();
	var province=e.target.value
	for(var k in cityList){
		if(province==cityList[k].province){
			var newCityList=cityList[k].cityList;
			var str='<option>选择市</option>';
			for(var i in newCityList){
				str+='<option value="'+newCityList[i].code+'">'+newCityList[i].name+'</option>'
			}
		}
	}
	$('#city').append(str);
});
// 方案接口dom生成函数
var planInf= function (res) {
  console.log(res);
  $('.table table .cece').remove();
  var rowNumber=0;
  
  var orderResultIdArr=[];
  for(var j in res.rows){
    orderResultIdArr.push(res.rows[j].orderResultId);
    var va=res.rows[j].orderInfo.va;
    var table=res.rows[j].orderInfo.media;
    var str='';
    var str1='';
    var str2='';
    var strAll='';
    var AllrowNum=0;

    for(var k in table){
      str2='';
      rowNumber=0;
      for(var i in table[k].nodes){
        rowNumber+=table[k].nodes[i].nodes.length;
        AllrowNum+=table[k].nodes[i].nodes.length;
        for(var a in table[k].nodes[i].nodes){ 
          if (a!=0) {
            str2+='<tr class="btbg1 cece"><td class=" boright">'+table[k].nodes[i].nodes[a].name+'</td>'+
            '<td class=" boright">'+table[k].nodes[i].nodes[a].number+'</td></tr>'
          }
        }
      }
      if (k!=0) {
        str1+='<tr class="btbg1 cece"><td rowspan="'+rowNumber+'" class=" boright">'+table[k].name+'</td>'+
        '<td class=" boright">'+table[k].nodes[0].nodes[0].name+'</td>'+
        '<td class=" boright">'+table[k].nodes[0].nodes[0].number+'</td></tr>'+str2
      }else{
        str1+=str2
      }
    }

    str='<tr class="btbg1 cece planindex">'+
    '<td rowspan="'+(Number(AllrowNum))+'" class=" boright plantitle">'+res.rows[j].OrderName+'</td>'+
    '<td rowspan="'+(Number(table[0].nodes[0].nodes.length))+'" class=" boright">'+table[0].name+'</td>'+
    '<td class=" boright">'+table[0].nodes[0].nodes[0].name+'</td>'+
    '<td class=" boright">'+table[0].nodes[0].nodes[0].number+'</td>'+
    '<td rowspan="'+(Number(AllrowNum))+'" class="">'+rounding(va.vaR,1,2)+'</td>'+
    '<td rowspan="'+(Number(AllrowNum))+'" class="">'+rounding(va.vaF,1,2)+'</td>'+
    '<td rowspan="'+(Number(AllrowNum))+'" class="">'+rounding(va.vaGRP,1,2)+'</td>'+
    '<td rowspan="'+(Number(AllrowNum))+'" class="">'+rounding(va.orderPrice,1,2)+'</td>'+
    '<td rowspan="'+(Number(AllrowNum))+'" class="">'+rounding(va.vaCPM,1,2)+'</td>'+
    '<td rowspan="'+(Number(AllrowNum))+'" class=""><a class="a_blue" href="media.html">点击查看详情</a></td>'+
    '</tr>'
    strAll=str+str1;
    $('.table table').append(strAll);
    // if (j%2==0) {
    //   console.log(j);
    //   $('.btbg1').removeClass('btbg1');
    // }
    
    // console.log(orderResultIdArr);
  }
  $('.table .a_blue').on('click',function () {
    var orderResultId=orderResultIdArr[$(this).parents('.planindex').index('.planindex')];
    sessionStorage.setItem('orderResultId',orderResultId);
  })
};
// 图表生成函数
var cityechartInf= function (data) {
 console.log(data)
 var cityDate= data.rows.cityDate;
 $('#cityIndex').html(cityDate.cityIndex);
 $('#brandIndex').html(cityDate.brandIndex);
 var str='';
 for (var k in cityDate.chanyeGDP) {
  str+=
  '<div class="echother clearfix">'+
  '<span class="othertitle"><i class="ech_iconcyan"></i>'+cityDate.chanyeGDP[k].type+'</span>'+
  '<span class="moneydata">'+
  '<div class="increments">'+cityDate.chanyeGDP[k].increments+'</div><div>亿</div></span>'+
  '<span><div>同比<b>'+rounding(cityDate.chanyeGDP[k].MOM,1,1)+'%'+'</b></div><div>环比<b>'+rounding(cityDate.chanyeGDP[k].YOY,1,1)+'%'+'</b></div></span>'+
  '<span><i class="ech_up"></i><i class="ech_down"></i></span></div>'
};
if($('echother')){
  $('.echother').remove();
}
// 显示生产总值
$('.echartother .echart').append(str);
var dataAxis=[];
var data=[];
for (var k in cityDate.hangyeGDP) {
 dataAxis.push(cityDate.hangyeGDP[k].type);
 data.push(cityDate.hangyeGDP[k].increments);
}
echarts.dispose(document.getElementById('echartGDP'));
    // 图表
    var myChartGDP = echarts.init(document.getElementById('echartGDP'));
    var yMax = 100;
    var dataShadow = [];
    for (var i = 0; i < data.length; i++) {
    	dataShadow.push(yMax);
    }
    var optionGDP = {
    	backgroundColor: ['#2d3039'],
    	textStyle:{
    		color:['#fff'],
    	},
    	tooltip: {
    		trigger: 'item',
    	},
    	xAxis: {
    		data: dataAxis,
    		axisLabel:{
    			interval : 0,
    			formatter:function(hangyetype)  
    			{  
    				var hy='';
    				if (hangyetype.length>3) {
    					hy= hangyetype.substring(0,3)+"…";
    				}else{
    					hy=hangyetype;
    				}
    				return hy.split("").join("\n");
    			}  
    		},
    		axisTick: {
    			show: false
    		},
    	},
    	yAxis: {
    		show:false,
    	},
    	dataZoom: [
    	{
    		type: 'inside'
    	}
    	],
    	series: [
      {
       type: 'bar',
       itemStyle: {
        normal: {color: 'rgba(57,61,73,0.4)'}
      },
      barGap:'-100%',
      barWidth: '30%',
      data: dataShadow,
      animation: false
    },
    {
     barWidth: '30%',
     type: 'bar',
     itemStyle: {
      normal: {
       color: function (params){
        if (params.dataIndex%2==0){
         return '#1e80ff';
       }else {
         return '#d905ff';
       }
     }
   },
   emphasis:{
   }
 },
 data: data
}
]
};
myChartGDP.setOption(optionGDP);

echarts.dispose(document.getElementById('echartCPI'));
var myChartCPI = echarts.init(document.getElementById('echartCPI'));
var dataCPItype=[];
var CPIMOM=[];
var CPIYOY=[];
for (var k in cityDate.CPI) {
 dataCPItype.push(cityDate.CPI[k].type);
 CPIMOM.push(rounding(cityDate.CPI[k].MOM,1,2));
 CPIYOY.push(rounding(cityDate.CPI[k].YOY,1,2));
}
;
var optionCPI = {
 backgroundColor: ['#2d3039'],
 textStyle:{
  color:['#fff'],
},
tooltip : {
  trigger: 'axis',
  axisPointer : {        
    type : 'shadow',        
    shadowStyle:{
     color:'#1683f6',
     opacity:0.5,
   }
 },
},
legend: {
  data:['同比','环比'],
  textStyle:{
   color:'#fff'
 }
},
grid: {
  left: '3%',
  right: '4%',
  bottom: '3%',
  containLabel: true
},
xAxis : [
{
  type : 'value',
  splitLine :{
   show:false
 }
}
],
yAxis : [
{
  type : 'category',
  data : dataCPItype
}
],
series : [
{
  color: ['#458DD9'],
  name:'同比',
  type:'bar',
  stack: '年份',
  data: CPIYOY,
  label: {
   normal: {
    show: true,
    fontSize:10,
    position: 'insideLeft',
    formatter: '{c}%'
  }
},
},
{
 color: ['#D8E6F6'],
 name:'环比',
 type:'bar',
 stack: '年份',
 data: CPIMOM,
 label: {
  normal: {
   show: true,
   position: 'insideRight',
   formatter: '{c}%'
 }
},
}
]
}
myChartCPI.setOption(optionCPI);
var hangyetype= [];
var hangyeMOM=[];
for (var k in cityDate.hangye) {
 hangyetype.push(cityDate.hangye[k].tpye)
 hangyeMOM.push(cityDate.hangye[k].MOM)
}
echarts.dispose(document.getElementById('echartHY'));
var myChartHY = echarts.init(document.getElementById('echartHY'));
var optionHY = {
 backgroundColor: ['#2d3039'],
 textStyle:{
  color:['#fff'],
},
tooltip : {
  trigger: 'axis',
  axisPointer: {
   type: 'cross',
   label: {
    backgroundColor: '#6a7985'
  }
}
},
xAxis : [
{
 type : 'category',
 boundaryGap : false,
 data : hangyetype,
 axisLabel:{
  interval : 0,
  formatter:function(hangyetype)  
  {  
   var hy='';
   if (hangyetype.length>3) {
    hy= hangyetype.substring(0,3)+"…";

  }else{
    hy=hangyetype;
  }
  return hy.split("").join("\n");
}  
},
}
],
yAxis : [
{
 type : 'value',
 splitLine :{
  show:false
}
}
],
series : [
{
 name:'同比',
 type:'line',
 stack: '行业',
 areaStyle: {normal: {}},
 symbol:"diamond",
 data:hangyeMOM,
 areaStyle:{
  normal:{opacity:0.5}
},
itemStyle:{
  normal:{color:'#1686fc'}
}
},
{
 name:'环比',
 type:'line',
 stack: '行业',
 areaStyle: {normal: {}},
 symbol:"diamond",
 areaStyle:{
  normal:{opacity:0.5}
},
itemStyle:{
  normal:{color:'#e100ff'}

}
}
]
};
myChartHY.setOption(optionHY);
var cityCharm=[];
var CharmNum=[];
for (var k in cityDate.cityCharm) {
  cityCharm.push(k);
  CharmNum.push(rounding(cityDate.cityCharm[k],1,2));
}
var  max=Math.max.apply(null, CharmNum);
    // console.log(CharmNum);
    echarts.dispose(document.getElementById('echartCharm'));
    var myChartCharm = echarts.init(document.getElementById('echartCharm'));

    var optionCharm = {
    	backgroundColor: ['#2d3039'],
    	textStyle:{
    		color:['#fff'],
    	},
    	tooltip: {
    		trigger: 'axis'
    	},
    	legend: {
        orient:'vertical',
        top:'112',
        right:'5',
        textStyle:{
         color:'#fff'
       }
     },
     radar: [
     {
       indicator: [
       { text: '商业魅力指数',max:max},
       { text: '商业资源聚集度指数',max:max},
       { text: '城市人口活跃度指数',max:max},
       { text: '城市枢纽性指数',max:max},
       { text: '生活方式多样性指数',max:max},
       { text: '未来可塑指数',max:max}
       ],

       center: ['50%', '50%'],
       radius: 90,
       splitNumber: 3,
       name: {
         formatter:'{value}',
         textStyle: {
          color:'#ffffff',
        }
      },
      splitArea: {
       areaStyle: {
        color: [
        'rgba(255, 255, 255, 0)'
        ],
        shadowColor: 'rgba(0, 0, 0, 0.3)',
        shadowBlur: 10
      }
    },
    axisLine: {
     lineStyle: {
      color: 'rgba(60, 64, 76, 0.9)'
    }
  },
  splitLine: {
   lineStyle: {
    color: 'rgba(60, 64, 76, 0.9)'
  }
}
}
],
series: [
{

 color:['#91c7ae','#749f83'],
 name: '雷达图',
 type: 'radar',
 tooltip: {
  trigger: 'item'
},
itemStyle: {
  normal: {
   areaStyle: {
    type: 'default',
  }
}
},
data: [
{
  value:CharmNum,
  itemStyle:{
   normal:{color:'#e100ff'}
 },
 areaStyle:{
   normal:{opacity:0.5},
   emphasis: {opacity:0.7}
 },
 name: '参数一',
 symbol: 'rect',
 symbolSize: 1,
},
]
}
]
}
myChartCharm.setOption(optionCharm);

var Brandname=[];
var Brandnumber=[];
for (var k in cityDate.BrandGroundNum) {
  Brandname.push(cityDate.BrandGroundNum[k].name)
  Brandnumber.push(cityDate.BrandGroundNum[k].number)
}
echarts.dispose(document.getElementById('echartBrand'));
var myChartBrand = echarts.init(document.getElementById('echartBrand'));
var optionBrand = {
  backgroundColor: ['#2d3039'],
  color:['#704ad0'],
  tooltip: {},
  textStyle:{
   color:['#fff'],
 },
 xAxis: {
   data:  Brandname,
   axisLabel:{
    interval : 0,
    formatter:function(hangyetype)  
    {  
     var hy='';
     if (hangyetype.length>3) {
      hy= hangyetype.substring(0,3)+"…";

    }else{
      hy=hangyetype;
    }
    return hy.split("").join("\n");
  }  
}
},
yAxis: {
 show:false,
},
series: [{
  type: 'bar',
  data: Brandnumber,
  barWidth: '30%',
}]
};
myChartBrand.setOption(optionBrand);
};
var ajaxUrl=url;
var cityListUrl=cityList;
var cityechartUrl=cityechart;
var mediaplanUrl=mediaplan;
var orderId=sessionStorage.getItem('orderId');
var orderIdData={
 orderId:orderId
};
//  页面登录获取对应的orderId的省市列表图表 方案数据
$(function(){
	var ajaxUrl=url;
	var cityListUrl=cityList;
	var cityechartUrl=cityechart;
	var mediaplanUrl=mediaplan;
	if(!sessionStorage.getItem('orderId')) {
		window.location.href='information.html';
		return false;
	}
	var orderId=sessionStorage.getItem('orderId');
	var orderIdData={
		orderId:orderId
	};
	getData('post',ajaxUrl,cityListUrl,orderIdData,cityDomList);
    // $('.city_info .a_blue').html($('#city option:selected').text());
    // // console.log(newCityList[0].code);
    // var cityCode = $('#city').val();
    // console.log($('#city').val());
    // var cityData={
    //     cityCode:cityCode
    // }
    // sessionStorage.setItem('cityCode',cityCode);
    // getData('post',ajaxUrl,cityechartUrl,cityData,cityechartInf);
    // var allInf={
    //     cityCode:sessionStorage.getItem('cityCode'),
    //     orderId:orderId
    // };
    // // console.log(cityCode);
    // getData('post',ajaxUrl,mediaplanUrl,allInf,planInf);

    // 图表数据接口
    $('#city').on('change',function() {
    	$('.city_info .a_blue').html($('#city option:selected').text());
    	var cityCode = $('#city').val();
    	var cityData={
    		cityCode:cityCode
    	}
      $('.city_info .a_blue').html('1');
      sessionStorage.setItem('cityCode',cityCode);
      getData('post',ajaxUrl,cityechartUrl,cityData,cityechartInf);
      var allInf={
        cityCode:sessionStorage.getItem('cityCode'),
        orderId:orderId
      };
      getData('post',ajaxUrl,mediaplanUrl,allInf,planInf);
    })
    setTimeout(function () {
      $('.city_info .a_blue').html($('#city option:selected').text());
    },1000)
    // $('.city_info .a_blue').html('1');
    // console.log($('#city option:selected').text());
  })
// var dataAxis = cityDate.hangyeGDP;

// 图表

